package org.wannatrak.android.formatter;

import android.content.Context;
import org.wannatrak.android.R;
import org.wannatrak.android.intf.Formatter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: Maksim Tulupov maxtulupov@gmail.com
 * @Date: $Date: 2011-06-14 13:32:03 +0000 (Tue, 14 Jun 2011) $ 5:47 PM
 * @version: $Revision: 2 $
 * @id: $Id: TimeFormatter.java 2 2011-06-14 13:32:03Z maxtulupov@gmail.com $
 */
public class TimeFormatter implements Formatter<Date> {

    protected DateFormat dateFormat;

    public TimeFormatter(Context context) {
        dateFormat = new SimpleDateFormat(context.getString(R.string.time_format));
    }

    public String format(Date value) {
        return value == null ? null : dateFormat.format(value);
    }

    public Date parse(String value) throws ParseException {
        return value == null || "".equals(value) ? null : dateFormat.parse(value);
    }
}
